package edu.yuhf.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import com.yuhf.db.utils.JdbcTemplate;

import edu.yuhf.dao.iface.HobbyDao;
import edu.yuhf.domain.Hobby;

public class HobbyJdbcDaoImpl implements HobbyDao {

	private static Logger log=Logger.getLogger(HobbyJdbcDaoImpl.class);
	@Override
	public List<Hobby> getHobbyAll() {
		String sql="select * from hobby";
		List<Hobby> list= JdbcTemplate.query(sql, (rs)->{
			List<Hobby> list0=new ArrayList<Hobby>();
			try {
				while(rs.next()) {
					Hobby hobby=new Hobby(rs.getInt(1),rs.getString(2),rs.getInt(3));
					list0.add(hobby);
				}
			} catch (SQLException e) {
				log.error("getHobbyAll method error,the exception is:"+e.getMessage());
			}
			return list0;
		}, new Object[] {});
		return list;
	}

}
